import {Component} from '@angular/core';
import {ProductService} from "../service/product.service";
import {NgForOf} from "@angular/common";

@Component({
  selector: 'app-main',
  standalone: true,
  imports: [
    NgForOf
  ],
  templateUrl: './main.component.html',
  styleUrl: './main.component.css'
})
export class MainComponent {
  productList: any[] = [];
  isVisible = false;


  constructor(private productService:ProductService) {
  }

  getProductListByCategory(href: string): void {
    this.productService.getProductVO(href)
      .subscribe(products => {
        this.productList = products?.data?.productList;
      });
  }

  showElement(): void {this.isVisible = true;}
  hideElement(): void {this.isVisible = false;}

  showInform(e: any) {
    // 获取url
    let target = e.target as HTMLAreaElement;
    let href = target.getAttribute("href");
    // @ts-ignore
    this.getProductListByCategory(href);
    // for (const value of this.productList.values()) {
    //   console.log(value);
    // }
    this.showElement();
  }

  protected readonly onmouseleave = onmouseleave;

  hideInform() {
    this.hideElement();
  }
}
